﻿
namespace CompositePattern;

public class Domain2 : AbstractDomain
{
    private List<Domain2> _domains = new List<Domain2>();
    public void AddChild(Domain2 domain)
    {
        _domains.Add(domain);
    }
    public override void Commission(double total)
    {
        double result = total * Percent / 100;
        Console.WriteLine($"This {Name} 提成 {result}");

        // 使用递归计算各个下级的提成
        foreach (Domain2 domain in _domains)
        {
            domain?.Commission(result);
        }
    }
}